package com.ycg.biquge.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ycg.biquge.common.Result;
import com.ycg.biquge.mapper.ChapterMapper;
import com.ycg.biquge.pojo.Chapter;
import com.ycg.biquge.service.ChapterService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YCG
 * @date 2024-04-29 21:04
 * @description 文章控制器
 */
@RestController
@RequestMapping("/chapter")
public class ChapterController {

    @Resource
    private ChapterMapper chapterMapper;



    /**
     * 根据id获取章节详细信息
     * @param id 文章id
     * @return 文章信息
     */
    @GetMapping("/{id}")
    public Result<Chapter> getById(@PathVariable String id){
        return Result.ok(chapterMapper.getOneById(Integer.valueOf(id)));
    }

    /**
     * 根据id和章节号获取章节详细信息
     * @param id 文章id
     * @param num 文章号
     * @return 文章信息
     */
    @GetMapping("/{id}/{num}")
    public Result<Chapter> getById(@PathVariable String id, @PathVariable String num){
        return Result.ok(chapterMapper.getOneByIdAndNum(Integer.valueOf(id),Integer.valueOf(num)));
    }
}
